<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" 
	xmlns:ui="http://java.sun.com/jsf/facelets" 
	xmlns:h="http://java.sun.com/jsf/html" 
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j" 
	xmlns:rich="http://richfaces.org/rich" 
	xmlns:c="http://java.sun.com/jstl/core" 
	xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<ui:composition>
	<f:loadBundle basename="mensagens" var="msg" />
	<c:if test="${empty rotulo}">
		<c:set var="rotulo" value="${msg[campo]}" />
	</c:if>
	<c:if test="${empty requerido}">
		<c:set var="requerido" value="false" />
	</c:if>
	<c:if test="${empty temRotulo}">
		<c:set var="temRotulo" value="true" />
	</c:if>
	<c:if test="${empty erroPopup}">
		<c:set var="erroPopup" value="true" />
	</c:if>
	<c:if test="${empty estiloRotulo}">
		<c:set var="estiloRotulo" value="${'estiloRotulo'}" />
	</c:if>
	<c:if test="${empty estiloCampo}">
		<c:set var="estiloCampo" value="${'estiloCampo'}" />
	</c:if>
	<c:if test="${empty filtroDependencia}">
		<c:set var="filtroDependencia" value="${'filtroId'}" />
	</c:if>
	<c:if test="${empty minDig}">
		<c:set var="minDig" value="${0}" />
	</c:if>
	<c:if test="${empty largura}">
		<c:set var="largura" value="${399}" />
	</c:if>
	<c:if test="${empty altura}">
		<c:set var="altura" value="${150}" />
	</c:if>
	<c:if test="${empty rendered}">
		<c:set var="rendered" value="${true}" />
	</c:if>
	<c:if test="${empty reRender}">
		<c:set var="reRender" value="${'asdasdasd'}" />
	</c:if>
	<c:set var="campoInput" value="${entidade}"/>
	<c:set var="indice" value="${0}"/>
	<c:forEach var="cadeia" items="${fn:split(campoTexto,'')}" varStatus="status">
		<c:if test="${cadeia == '.'}">
			<c:set var="campoInput" value="${campoInput[fn:substring(campoTexto,indice,status.index - 1)]}"/>
			<c:set var="indice" value="${status.index}"/>
		</c:if>
		<c:if test="${status.last}">
			<c:set var="campoInput" value="${campoInput[fn:substring(campoTexto,indice,status.index)]}"/>
		</c:if>
	</c:forEach>
	<c:if test="#{temRotulo}">
		<h:panelGroup rendered="${rendered}" id="${id}PanelLabel">
			<c:if test="#{requerido}"><h:graphicImage id="${id}Image" value="/images/icons/asterisco.png" styleClass="imgRequerido"/></c:if>
			<h:outputLabel styleClass="#{estiloRotulo}" id="${id}Label" value="#{rotulo}:" />
			<c:if test="${!erroPopup}">
				<h:message id="${id}Error" style="color: red;" for="#{id}Hidden" />
			</c:if>
		</h:panelGroup>
	</c:if>
	<h:panelGroup rendered="${rendered}" id="${id}PanelInput">
		<c:if test="${!(empty varId)}">
			<h:inputText id="${id}Hidden" value="#{entidade[campoCodigo]}" required="${requerido}" label="${rotulo}" style="width:0px;height:0px;top:-5000px;position:absolute;"/>
		</c:if>
		<a4j:loadScript id="#{id}ScriptTemplate" src="resource:///cssjs/template.js" />
		<a4j:loadStyle id="#{id}StyleTemplate" src="resource:///cssjs/template.css" />
		<h:panelGrid id="${id}PanelSuggestion" columns="2" border="0" cellpadding="0" cellspacing="0">
			<h:inputText id="${id}Input" style="margin:0px;width:${largura-79}px;margin-right:-1px;" value="${campoInput}" onblur="verificarCampoVazio(document.getElementById('${idForm}:${id}Input'), document.getElementById('${idForm}:${id}Hidden'), ${minDig});" onkeydown="return event.keyCode != 13;">
				<c:if test="${!(empty campoCodigoDependencia)}">
					<a4j:support id="${id}SupportOnfocus" event="onfocus" ajaxSingle="true">
						<f:setPropertyActionListener value="#{entidade[campoCodigoDependencia]}" target="#{varLista[filtroDependencia]}" />
					</a4j:support>
				</c:if>
			</h:inputText>
			<h:graphicImage id="${id}ImageSeta" value="/images/icons/arrowin.png" onclick="document.getElementById('${idForm}:${id}Sugestao').component.callSuggestion(true)"
				style="vertical-align:top;">
				<c:if test="${!(empty campoCodigoDependencia)}">
					<a4j:support id="${id}SupportOnclick" event="onclick" ajaxSingle="true" oncomplete="document.getElementById('${idForm}:${id}Sugestao').component.callSuggestion(true)">
						<f:setPropertyActionListener value="#{entidade[campoCodigoDependencia]}" target="#{varLista[filtroDependencia]}" />
					</a4j:support>
				</c:if>
			</h:graphicImage>
		</h:panelGrid>

		<rich:suggestionbox height="${altura}" width="${largura}" minChars="${minDig}" usingSuggestObjects="true" nothingLabel="Nenhum registro encontrado."
			onobjectchange="sugestaoJSHidden(document.getElementById('${idForm}:${id}Input'), document.getElementById('${idForm}:${id}Hidden'), document.getElementById('${idForm}:${id}Sugestao').component.getSelectedItems().pluck('${varId}'), document.getElementById('${idForm}:${idFilho}Input'), document.getElementById('${idForm}:${idFilho}Hidden'));"
			suggestionAction="${varLista[varNomeLista]}" var="sugestao" for="${id}Input" id="${id}Sugestao" selectValueClass="rowSuggestionSelected">
			<c:if test="${empty varId}">
				<c:set var="selecaoOrigem" value="#{sugestao}" />
				<c:set var="selecaoDestino" value="#{entidade}" />
			</c:if>
			<c:if test="${!(empty varId)}">
				<c:set var="selecaoOrigem" value="#{sugestao[varId]}" />
				<c:set var="selecaoDestino" value="#{entidade[campoCodigo]}" />
			</c:if>
			<a4j:support id="${id}SupportOnselect" event="onselect" ajaxSingle="true" reRender="${reRender}" oncomplete="${onselectcomplete}">
				<f:setPropertyActionListener value="#{selecaoOrigem}" target="#{selecaoDestino}" />
			</a4j:support>
			<c:if test="${!(empty varTexto)}">
				<h:column>
					<h:outputText id="sugestaoTexto" value="#{sugestao[varTexto]}" />
				</h:column>
			</c:if>
			<ui:insert />
		</rich:suggestionbox>
	</h:panelGroup>
</ui:composition>
</html>